
		$(document).ready(function(){
			var table=$("#permissionTable");
			var keyword="";	
			var t=table.dataTable({
				"ajax":function(data,callback,setting){
					var page = table.api().page.info();
					$.post("/index.php?m=Admin&c=Customer&a=search",{pageIndex:page.page+1,pageSize:page.length,select:keyword},function(data,status){
						console.log(data);
							callback(data);	
					});
				},
				// ajax:{
				// 	url:"/index.php?m=Admin&c=Customer&a=index"
				// },
 				"pageLength":10,
  				"ordering":false,
          "deferRender": true,
  				"columns":[
  				{"data":"id"},
          {"data":"id"},
  				{"data":"customer_no"},
  				{"data":"name"},
  				{"data":"sex"},
          {"data":"tel"},
  				{"data":"ugroup"},
  				{"data":"status"},
          {"data":"id"},
  				],
  				"columnDefs":[
  				{
  					"targets":0,
  					"data":"id",
  					"render":function(data,type,full,meta){
  						return '<input type="checkbox" value="'+data+'" name="customer">';
  					}

  				},
  				{
  					"targets":7,
  					"data":"status",
  					"render":function(data,type,full,meta){
  						var str="";
  						switch(data){
  							case "0":
  							str='<span class="label radius state">已停用</span>';
  							break;
  							case "1":
  							str='<span class="label label-success radius state">已启用</span>';
  							break;
  						}
  						return str;
  					}
  				},
          {
            "targets":4,
            "data":"sex",
            "render":function(data,type,full,meta){
              var str="";
              switch(data){
                case "M":
                str="男";
                break;
                case "F":
                str='女';
                break;
              }
              return str;
            }
          },
  				{
  					"targets":8,
  					"data":"id",
  					"render":function(data,type,full,meta){
  						var str='<a style="text-decoration:none"  href="javascript:;" title="启用" class="start" uid='+data+'><i class="Hui-iconfont"></i></a><a title="编辑" href="javascript:;" uid="'+data+'" class="ml-5 customerEdit" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a><a title="删除" href="javascript:;" uid="'+data+'" class="ml-5 customerDel uid-'+data+'" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>';
  						return str;
  					}

  				},
  				],
  			"fnCreatedRow":function(row,data,index){
  				//row 表示当前tr，data表示当前行的元素对象，index表示当前tr索引
  				var status=$(row).find(".state").text();
          if(status=='已启用'){
            $(row).find(".start").attr("title",'停用');
            $(row).find(".start i").addClass('Hui-iconfont-shenhe-tingyong')
          }else{
             $(row).find(".start").attr("title",'启用');
              $(row).find(".start i").addClass('Hui-iconfont-gouxuan');
          }
  			},
  			
			"bPaginate": true, //翻页功能
			"searching":false,
			// "processing": true,
        	"serverSide": true,//服务器模式
        			// 	"infoCallback": function( settings, start, end, max, total, pre ) {
  //  				table.DataTable().ajax.reload();
  // },

        });
		$(".searchButton").click(function(){
			keyword=$("#searchName").val();
			t.api().draw();
		});
		// 回车事件
		document.onkeydown = function(e){
                 var ev = document.all ? window.event : e;
                 if(ev.keyCode==13) {
                    keyword=$("#searchName").val();
                    t.api().draw();
                 }
            }
	});